package com.totem.admin.service.impl;

import com.totem.admin.service.IAdminProductService;
import com.totem.admin.vo.FileUrlVO;
import com.totem.base.constants.ErrorCode;
import com.totem.base.enums.FileTypeEnum;
import com.totem.base.exception.BaseException;
import com.totem.base.util.S3Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.services.s3.S3Client;

@Slf4j
@Service
public class AdminProductServiceImpl implements IAdminProductService {
    @Autowired
    private S3Client s3Client;

    @Override
    public FileUrlVO uploadFileCover(MultipartFile file) {
        long size = file.getSize();
        if(size>1024*1024*40){
            throw new BaseException(ErrorCode.FILE_UPLOAD_IMG_TOO_LARGE);
        }
        return S3Util.uploadFile(s3Client, file, FileTypeEnum.COVER.getCode());
    }

    @Override
    public FileUrlVO uploadFileCarousel(MultipartFile file) {
        long size = file.getSize();
        if(size>1024*1024*40){
            throw new BaseException(ErrorCode.FILE_UPLOAD_IMG_TOO_LARGE);
        }
        return S3Util.uploadFile(s3Client, file, FileTypeEnum.CAROUSEL.getCode());
    }

    @Override
    public FileUrlVO uploadFileVideo(MultipartFile file) {
        long size = file.getSize();
        if(size>1024*1024*200){
            throw new BaseException(ErrorCode.FILE_UPLOAD_VIDEO_TOO_LARGE);
        }
        return S3Util.uploadFile(s3Client, file, FileTypeEnum.VIDEO.getCode());
    }
}
